﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<QianBuo.Lottery.Web.Models.Play.PlayTypeModel>" %>
<%@ Import Namespace="Code.Models" %>
<div>
    <div id="play_inputpanel">
    <%
        var RenXuanEr = (PlayType_E)ViewData["RenXuanEr"];
        var RenXuanSan = (PlayType_E)ViewData["RenXuanSan"];
        var RenXuanSi = (PlayType_E)ViewData["RenXuanSi"];
        var RenXuanWu = (PlayType_E)ViewData["RenXuanWu"];    
        %>
        <table border="0" cellpadding="0" cellspacing="5" class="play_play_input" align="center">
            <tr id="input_model">
                <td width="60px">
                    &nbsp;
                </td>
                <td colspan="17" align="left">
                   <input type="radio" name="inputtype" class='type<%=(int)RenXuanEr %>'  id='任选二' value='<%=(int)RenXuanEr %>' surl='<%=Url.RouteUrl("Play_Single",new{p1=RenXuanEr}) %>' /><label for='任选二'>任选二</label>
                   <input type="radio" name="inputtype" class='type<%=(int)RenXuanSan %>' id='任选三' value='<%=(int)RenXuanSan %>' surl='<%=Url.RouteUrl("Play_Single",new{p1=RenXuanSan}) %>' /><label for='任选三'>任选三</label>
                   <input type="radio" name="inputtype" class='type<%=(int)RenXuanSi %>'  id='任选四' value='<%=(int)RenXuanSi %>' surl='<%=Url.RouteUrl("Play_Single",new{p1=RenXuanSi}) %>' /><label for='任选四'>任选四</label>
                   <input type="radio" name="inputtype" class='type<%=(int)RenXuanWu %>' id='任选五' value='<%=(int)RenXuanWu %>' surl='<%=Url.RouteUrl("Play_Single",new{p1=RenXuanWu}) %>' /><label for='任选五'>任选五</label>
                </td>
            </tr>
            <tr class="tr_number" id="p10">
                <td class="head">
                    小
                </td>
                <td class="number">
                    1
                </td>
                <td class="number">
                    2
                </td>
                <td class="number">
                    3
                </td>
                <td class="number">
                    4
                </td>
                <td class="number">
                    5
                </td>
                <td class="number">
                    6
                </td>
                <td class="number">
                    7
                </td>
                <td class="number">
                    8
                </td>
                <td class="number">
                    9
                </td>
                <td class="number">
                    10
                </td>
                <td>
                    &nbsp;
                </td>
                <td class="tool">
                    全
                </td>
                <td class="tool">
                    大
                </td>
                <td class="tool">
                    小
                </td>
                <td class="tool">
                    奇
                </td>
                <td class="tool">
                    偶
                </td>
                <td class="tool">
                    清
                </td>
            </tr>
            <tr class="tr_number" id="p100">
                <td class="head">
                    大
                </td>
                <td class="number">
                    11
                </td>
                <td class="number">
                    12
                </td>
                <td class="number">
                    13
                </td>
                <td class="number">
                    14
                </td>
                <td class="number">
                    15
                </td>
                <td class="number">
                    16
                </td>
                <td class="number">
                    17
                </td>
                <td class="number">
                    18
                </td>
                <td class="number">
                    19
                </td>
                <td class="number">
                    20
                </td>
                <td>
                    &nbsp;
                </td>
                <td class="tool">
                    全
                </td>
                <td class="tool">
                    大
                </td>
                <td class="tool">
                    小
                </td>
                <td class="tool">
                    奇
                </td>
                <td class="tool">
                    偶
                </td>
                <td class="tool">
                    清
                </td>
            </tr>
            <tr id="playinfo">
                <td colspan="18" style="text-align:left">
                    <%=Model.Remark %>
                </td>
            </tr>
            <tr>
                <td colspan="8" id="sumcount">
                    注数:<font color="red">0</font>
                </td>
                <td colspan="10" align="left">
                    <input type="button" name="bet_play_btnadd" id="bet_play_btnadd" value="添加" class="bet_play_btnadd"
                        onclick="RenXuan.addScheme()" />
                </td>
            </tr>
        </table>
        <script type="text/javascript">
              var __playid=<%=Model.PlayID %>;
            $(document).ready(showWinInfo);
            function showWinInfo(){
                var pwin = Site.Lottery.Bet.GetPlayTypeWinMoney(function(item){ return item.PlayTypeID == __playid;});
                if(pwin != null)
                    $('<span><%=string.IsNullOrEmpty(Model.Remark) ? "" : "，" %>'+"奖金:<font color='red'>"+pwin.WinMoney+"元</font></span>").appendTo($("#playinfo td"));
                else
                    window.setTimeout(showWinInfo,500);
            }

            $(".play_play_input .number").click(function () {
             var text="";
                var item = $(this);
                var id = item.parent().attr("id");
                if (item.is(".select")) {
              
                    item.removeClass("select");
                    if(id=="p100")
                    {
                       RenXuan.ChooseNumber100=RenXuan.ChooseNumber100.replace((item.text()+""),'');
                       RenXuan.ChooseNumber100Count--;
                    }
                    else
                    {
                     
                       RenXuan.ChooseNumber10=RenXuan.ChooseNumber10.replace((item.text()+""),'');
                       RenXuan.ChooseNumber10Count--;
                     
                    }
                   
                }
                else {
                
                    item.addClass("select");
                   
                  if(id=="p100")
                    {
                       RenXuan.ChooseNumber100+=item.text()+"";
                       RenXuan.ChooseNumber100Count++;
                    }
                    else
                    {
                       RenXuan.ChooseNumber10+=item.text()+"";
                       RenXuan.ChooseNumber10Count++;
                    }
                   
                }

              var count = RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count;
              $("#任选二").attr("checked", function(index, attr) {
                 if (attr == true) {
                 $(".play_play_input #sumcount font").html('0');
                           var n = 1;
                    for (var a = count-1; a <= count; a++) {
                             n = n * a;
                        }
                   var m=1;
                   for(var i=1;i<3;i++)
                   {
                       m=m * i;
                   }
                   count=n/m;
                $(".play_play_input #sumcount font").html(count);
               }
               });
                $("#任选三").attr("checked", function(index, attr) {
                 
                 if (attr == true) {
                 $(".play_play_input #sumcount font").html('0');
                   var n = 1;
                    for (var a = count-2; a <= count; a++) {
                             n = n * a;
                        }
                   var m=1;
                   for(var i=1;i<4;i++)
                   {
                       m=m * i;
                   }
                   count=n/m;
                    $(".play_play_input #sumcount font").html(count);
                 } });
                   $("#任选四").attr("checked", function(index, attr) {
                  
                 if (attr == true) {
                   $(".play_play_input #sumcount font").html('0');
                   var n = 1;
                    for (var a = count-3; a <= count; a++) {
                             n = n * a;
                        }
                   var m=1;
                   for(var i=1;i<5;i++)
                   {
                       m=m * i;
                   }
                   count=n/m;
                    $(".play_play_input #sumcount font").html(count);
                 } });
                  $("#任选五").attr("checked", function(index, attr) {
                   
                 if (attr == true) {
                 $(".play_play_input #sumcount font").html('0');
                   var n = 1;
                    for (var a = count-4; a <= count; a++) {
                             n = n * a;
                        }
                   var m=1;
                   for(var i=1;i<6;i++)
                   {
                       m=m * i;
                   }
                   count=n/m;
                    $(".play_play_input #sumcount font").html(count);
                 } });
            });
            RenXuan={};

            $(".play_play_input .tool").click(function () {
                RenXuan.selectNumber($(this).parent().find(".number"), this.innerText);
               
            });
            RenXuan.ChooseNumber=[];
            RenXuan.PlayModels=[];
            RenXuan.ChooseNumber100="";
            RenXuan.ChooseNumber10="";
            RenXuan.ChooseNumber10Count=0;
            RenXuan.ChooseNumber100Count=0;

            RenXuan.PlayID=<%=Model.ID %>;
            RenXuan.PlayName='<%=Model.Name%>';
            
            RenXuan.SetCurrentPlay = function(id, name) {
                RenXuan.PlayID = id;
                RenXuan.PlayName = name;

                Site.Lottery.Bet.SetCurrentPlay(RenXuan.PlayID, RenXuan.PlayName);
            };

            RenXuan.addScheme = function() {

                if ((RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count) == 0) {
                    alert('号码选择不正确！');
                    return;
                }
                if (RenXuan.ChooseNumber10 != "" && RenXuan.ChooseNumber100 != "") {
                    RenXuan.ChooseNumber10 = RenXuan.ChooseNumber10.substring(0, RenXuan.ChooseNumber10.lastIndexOf(" "));
                    var number = RenXuan.ChooseNumber10 + "," + RenXuan.ChooseNumber100;
                    number = number.substring(0, number.lastIndexOf(" "));
                } else if (RenXuan.ChooseNumber10 == "") {
                    var number = RenXuan.ChooseNumber100;
                    number = number.substring(0, number.lastIndexOf(" "));
                } else {
                    var number = RenXuan.ChooseNumber10;
                    number = number.substring(0, number.lastIndexOf(" "));
                }

                var count = RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count;
                RenXuan.PlayModels['任选二'] = { ID: '<%=(int)ViewData["RenXuanEr"] %>', Name: '<%=((PlayType_E)ViewData["RenXuanEr"]).GetName() %>', Numbers: '' };
                RenXuan.PlayModels['任选三'] = { ID: '<%=(int)ViewData["RenXuanSan"] %>', Name: '<%=((PlayType_E)ViewData["RenXuanSan"]).GetName() %>', Numbers: '' };
                RenXuan.PlayModels['任选四'] = { ID: '<%=(int)ViewData["RenXuanSi"] %>', Name: '<%=((PlayType_E)ViewData["RenXuanSi"]).GetName() %>', Numbers: '' };
                RenXuan.PlayModels['任选五'] = { ID: '<%=(int)ViewData["RenXuanWu"] %>', Name: '<%=((PlayType_E)ViewData["RenXuanWu"]).GetName() %>', Numbers: '' };
                if (Site.Lottery.Bet) {
                    $("#任选三").attr("checked", function(index, attr) {
                        if (attr == true) {
                            if ((RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count) < 3) {
                                alert('号码选择不正确！');
                                return;
                            }
                            var n = 1;
                            for (var a = count - 2; a <= count; a++) {
                                n = n * a;
                            }
                            var m = 1;
                            for (var i = 1; i < 4; i++) {
                                m = m * i;
                            }
                            count = n / m;
                            Site.Lottery.Bet.AddPlayItem(RenXuan.PlayModels["任选三"].ID, RenXuan.PlayModels["任选三"].Name, number, count, 1)
                        }
                    });
                    $("#任选四").attr("checked", function(index, attr) {
                        if (attr == true) {
                            if ((RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count) < 4) {
                                alert('号码选择不正确！');
                                return;
                            }
                            var n = 1;
                            for (var a = count - 3; a <= count; a++) {
                                n = n * a;
                            }
                            var m = 1;
                            for (var i = 1; i < 5; i++) {
                                m = m * i;
                            }
                            count = n / m;
                            Site.Lottery.Bet.AddPlayItem(RenXuan.PlayModels["任选四"].ID, RenXuan.PlayModels["任选四"].Name, number, count, 1)
                        }
                    });
                    $("#任选五").attr("checked", function(index, attr) {
                        if (attr == true) {
                            if ((RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count) < 5) {
                                alert('号码选择不正确！');
                                return;
                            }
                            var n = 1;
                            for (var a = count - 4; a <= count; a++) {
                                n = n * a;
                            }
                            var m = 1;
                            for (var i = 1; i < 6; i++) {
                                m = m * i;
                            }
                            count = n / m;
                            Site.Lottery.Bet.AddPlayItem(RenXuan.PlayModels["任选五"].ID, RenXuan.PlayModels["任选五"].Name, number, count, 1)
                        }
                    });
                    $("#任选二").attr("checked", function(index, attr) {
                        if (attr == true) {
                            if ((RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count) < 2) {
                                alert('号码选择不正确！');
                                return;
                            }
                            var n = 1;
                            for (var a = count - 1; a <= count; a++) {
                                n = n * a;
                            }
                            var m = 1;
                            for (var i = 1; i < 3; i++) {
                                m = m * i;
                            }
                            count = n / m;
                            Site.Lottery.Bet.AddPlayItem(RenXuan.PlayID, "任选二", number, count, 1)
                        }
                    });
                }
                $(".number").removeClass("select");
                RenXuan.ChooseNumber100 = "";
                RenXuan.ChooseNumber10 = "";
                RenXuan.ChooseNumber10Count = 0;
                RenXuan.ChooseNumber100Count = 0;
                $(".play_play_input #sumcount font").html('0');

            };

            RenXuan.selectNumber = function(numbers, type) {

                numbers.each(function() {
                    $(this).removeClass("select");
                    var id = $(this).parent().attr("id");

                    if (id == "p100") {

                        RenXuan.ChooseNumber100 = "";
                        RenXuan.ChooseNumber100Count = 0;
                    } else if (id = "p10") {

                        RenXuan.ChooseNumber10 = "";
                        RenXuan.ChooseNumber10Count = 0;
                    }
                });

                RenXuan.ChooseNumber[numbers.parent().attr("id")] = '';
                $(".play_play_input #sumcount font").html('0');
                type = type.replace(/\s+/g, "");
                switch (type) {
                case "全":
                    numbers.click();
                    break;
                case "大":
                    numbers.each(function() {
                        if ((parseInt(this.innerText) > 5 && parseInt(this.innerText) < 11) || (parseInt(this.innerText) > 15 && parseInt(this.innerText) < 21))
                            $(this).click();
                    });
                    break;
                case "小":
                    numbers.each(function() {
                        if ((parseInt(this.innerText) < 6) || (parseInt(this.innerText) > 10 && parseInt(this.innerText) < 16))                          
                            $(this).click();
                    });
                    break;
                case "奇":
                    numbers.each(function() {
                        if (parseInt(this.innerText) % 2 == 1)
                            $(this).click();
                    });
                    break;
                case "偶":
                    numbers.each(function() {
                        if (parseInt(this.innerText) % 2 == 0)                                 
                            $(this).click();

                    });
                    break;
                case "清":
                    numbers.each(function() {

                        var count = RenXuan.ChooseNumber100Count + RenXuan.ChooseNumber10Count;
                        $("#任选二").attr("checked", function(index, attr) {
                            if (attr == true) {
                                $(".play_play_input #sumcount font").html('0');
                                var n = 1;
                                for (var a = count - 1; a <= count; a++) {
                                    n = n * a;
                                }
                                var m = 1;
                                for (var i = 1; i < 3; i++) {
                                    m = m * i;
                                }
                                count = n / m;
                                $(".play_play_input #sumcount font").html(count);
                            }
                        });
                        $("#任选三").attr("checked", function(index, attr) {

                            if (attr == true) {
                                $(".play_play_input #sumcount font").html('0');
                                var n = 1;
                                for (var a = count - 2; a <= count; a++) {
                                    n = n * a;
                                }
                                var m = 1;
                                for (var i = 1; i < 4; i++) {
                                    m = m * i;
                                }
                                count = n / m;
                                $(".play_play_input #sumcount font").html(count);
                            }
                        });
                        $("#任选四").attr("checked", function(index, attr) {

                            if (attr == true) {
                                $(".play_play_input #sumcount font").html('0');
                                var n = 1;
                                for (var a = count - 3; a <= count; a++) {
                                    n = n * a;
                                }
                                var m = 1;
                                for (var i = 1; i < 5; i++) {
                                    m = m * i;
                                }
                                count = n / m;
                                $(".play_play_input #sumcount font").html(count);
                            }
                        });
                        $("#任选五").attr("checked", function(index, attr) {

                            if (attr == true) {
                                $(".play_play_input #sumcount font").html('0');
                                var n = 1;
                                for (var a = count - 4; a <= count; a++) {
                                    n = n * a;
                                }
                                var m = 1;
                                for (var i = 1; i < 6; i++) {
                                    m = m * i;
                                }
                                count = n / m;
                                $(".play_play_input #sumcount font").html(count);
                            }
                        });
                    });
                    break;                     
                }

            };
            RenXuan.PlayModels['任选二'] = {ID:'<%=(int)ViewData["RenXuanEr"] %>',Name:'<%=((PlayType_E)ViewData["RenXuanEr"]).GetName() %>',Numbers:''};
            RenXuan.PlayModels['任选三'] = {ID:'<%=(int)ViewData["RenXuanSan"] %>',Name:'<%=((PlayType_E)ViewData["RenXuanSan"]).GetName() %>',Numbers:''};
            RenXuan.PlayModels['任选四'] = {ID:'<%=(int)ViewData["RenXuanSi"] %>',Name:'<%=((PlayType_E)ViewData["RenXuanSi"]).GetName() %>',Numbers:''};
            RenXuan.PlayModels['任选五'] = {ID:'<%=(int)ViewData["RenXuanWu"] %>',Name:'<%=((PlayType_E)ViewData["RenXuanWu"]).GetName() %>',Numbers:''};
            var isSingle=<%="true".Equals(TempData["singleplay"] as string)?"true":"false" %>;
            $("#input_model :radio").each(function() {
                var item = $(this)
                item.click(function() {
                    var val = parseInt(this.value);
                    $(".play_play_input #sumcount font").html('0');
                    RenXuan.ChooseNumber100 = "";
                    RenXuan.ChooseNumber10 = "";
                    RenXuan.ChooseNumber10Count = 0;
                    RenXuan.ChooseNumber100Count = 0;
                    $(".number").removeClass("select");
                    var play = RenXuan.PlayModels[this.id];
                    if (this.value == -1){
                        $(".play_play_input #sumcount font").html('0');
                        RenXuan.SetCurrentPlay(play.ID, play.Name);
                    } else {
                        $(".play_play_input #input_" + this.value + " .number:first").click().click();

                        if (RenXuan.PlayID == val) {
                            RenXuan.SetCurrentPlay(play.ID, play.Name);
                            return;
                        }
                        if (isSingle) {
                            location.href = item.attr('surl');
                            return;
                        }
                        var url = '<%=Url.Action("Play",new {p1="!"}) %>/'.replace("!", val);
                        $("#play_bet_bar").block({ message: "<img src='<%=Url.Content("~/Content/images/busy.gif") %>'/>载入中...", css: { cursor: "default" }, overlayCSS: { cursor: "default" } });
                        $("#play_bet_bar").load(url, null, function(p, e, i) {
                            $("#play_bet_bar").unblock();
                            if (e == 'success' && $(p).has("#play_inputpanel")) {
                            } else {
                                $("#input_model .type" + val).click();
                                return false;
                            }
                        });
                    }
                });
                if (RenXuan.PlayID == parseInt(item.val()))
                    this.checked = true;
            });
            $("#input_model :radio:checked").click();
        </script>
    </div>
</div>
